<ul class="nav nav-tabs">
	<li class="active"><a href="javascript:;">自动安装官方免费应用</a></li>
</ul>
<div class="form-horizontal form">
<div class="panel panel-info">
	<div class="panel-body">
		<div id="show_title" class="today" style="padding:5px">正在安装准备数据，请勿关闭浏览器！</div>
		<div id="showewm" style="margin-top:.5em;">
				<img src="../core/resource/images/loading.gif" width="100" />
		</div>
		<div id="show_message" style="font-size:16px;"></div>
		
	</div>
</div>
</div>
<script>	
	scope.pagedata.get=function(step){	
		if(!scope.pagedata.apps[step]){
			setTimeout(function(){
				$('#page-loading').hide();
				scope.message('官方基础应用安装成功！','','/system.welcome/');
			},1000);
		}
		var item=scope.pagedata.apps[step];
		
		scope.pagedata.add_message('准备获取待安装'+item.title+'列表...');
		post={'plugin':'core','action':'cloud.initialize','op':item.get_op};
		scope.ajax(post,'',function(result){
			if(result.type=='success'){
				//plugins=result.message.list;
				scope.pagedata.add_message('待安装'+item.title+'获取成功！');
				scope.pagedata.install(result.message.list,step);
				
			}else{
				scope.pagedata.add_message('待安装'+item.title+'获取失败！原因：'+result.message);
			}
		},false,true);
	}
	scope.pagedata.install=function(list,step,index){
		if(!index){
			index=0;
		}
		if(!list[index]){
			step++;
			scope.pagedata.get(step);
		}
		var item=list[index];
		scope.pagedata.add_message('准备安装'+scope.pagedata.apps[step].title+'【'+item.title+'】...');
		var post={'plugin':'core','action':scope.pagedata.apps[step].install_action,'op':'install','id':item.id};
		scope.ajax(post,'',function(result){
			if(result.type=='success'){
				scope.pagedata.add_message(scope.pagedata.apps[step].title+'【'+item.title+'】安装成功！');
				index++;
				scope.pagedata.install(list,step,index);
			}
		},false,true);
	}
	scope.pagedata.start=function(){
		scope.pagedata.add_message('准备购买免费官方应用...');
		var post={'plugin':'core','action':'cloud.update','op':'buy'};
		scope.ajax(post,'',function(result){
			if(result.type=='success'){
				scope.pagedata.add_message('免费官方应用购买成功！');
				scope.pagedata.get(0);
			}
			setTimeout(function(){
					$('#page-loading').show();
			},500);
		},false,true);
	}
	scope.pagedata.add_message=function(msg){
		msg='<div>'+msg+'</div>';
		$('#show_message').append(msg);
	}
	scope.pagedata.start();
</script>